import request from "/utils/omsRequest";

Page({
  data: {
    merchants: []
  },
  onLoad() { },
  jumpToNewContract(e) {
    dd.showLoading({
      content: '加载中...'
    })
    request({
      url: "/ajax/merchant/merchantIntegrity",
      data: {
        merchantId: e.target.dataset.id
      }
    }).then(() => {
      dd.hideLoading()
      dd.redirectTo({
        url: `/pages/contract/newContract/newContract?id=${e.target.dataset.id}`
      })
    }).catch(err => {
      if (err === "请补充完整商户信息添加合同") {
        dd.alert({
          title: "跳转通知",
          content: "请补充完整商户信息添加合同",
          buttonText: '确定',
          success: () => {
            dd.redirectTo({
              url: `/pages/merchant/modifyMerchant/modifyMerchant?id=${e.target.dataset.id}`
            });
          },
        });
      }
    })
  },
  onSearchMerchant(e) {
    if (e.detail.value) {
      request({
        url: "/ajax/merchant/findSelect",
        data: {
          vague: e.detail.value
        }
      }).then(res => {
        this.setData({
          merchants: res.voList
        });
      })
    } else {
      this.setData({
        merchants: []
      });
    }
  }
});
